<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Vue List Example</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item, index) in list" :key="index">
                {{ item }}
                <button @click="removeItem(index)">删除</button>
            </li>
        </ul>
        <button @click="generateItem">生成</button>
    </div>
    <script>
        new Vue({
            el: '#app',
            data: {
                list: [1, 5, 3]
            },
            methods: {
                generateItem() {
                    // 生成20以内的随机数
                    let randomNumber = Math.floor(Math.random() * 20 + 1);
                    this.list.push(randomNumber);
                },
                removeItem(index) {
                    this.list.splice(index, 1);
                }
            }
        });
    </script>
</body>

</html>